<template>
	<view class="list-view">
		<view class="top-bar"><uni-navbar :fixed="true" :back="true" color="#fff" title="建议办理"></uni-navbar></view>

		<u-row class="link-box" gutter="0" align="top">
			<u-col span="3" v-if="$sysMenus('motion_add')">
				<navigator hover-class="none" class="link-item" url="/pagesB/proposal/add">
					<image src="/static/img/icon_28.png" mode="aspectFill"></image>
					提交建议
				</navigator>
			</u-col>
			<u-col span="3">
				<navigator hover-class="none" class="link-item" url="/pagesB/proposal/list">
					<image src="/static/img/icon_30.png" mode="aspectFill"></image>
					我的建议
				</navigator>
			</u-col>
			<u-col span="3" v-if="$sysMenus('motion_add')">
				<navigator hover-class="none" class="link-item" url="/pagesB/proposal/spare_list?status=0">
					<image src="/static/img/icon_31.png" mode="aspectFill"></image>
					草稿箱
				</navigator>
			</u-col>
			<u-col span="3" v-if="$sysMenus('proposals_statistics')">
				<navigator hover-class="none" class="link-item" url="/pagesB/proposal/statistics">
					<image src="/static/img/icon_89.png" mode="aspectFill"></image>
					统计分析
				</navigator>
			</u-col>
		</u-row>

		<view class="com-h2">
			<text class="h2-title">总体概况</text>
			<text class="h2-col">截止{{ new Date() | parseTime('{y}.{m}.{d} {h}:{i}') }}</text>
		</view>
		<view class="plus-inner">
			<view class="plus-box">
				<view class="plus-item bg92" @click="listTo('/pagesB/proposal/list')">
					<view class="title">{{ numAll }}</view>
					<view>我的建议</view>
				</view>
				<view class="plus-item bg93" @click="listTo('/pagesB/proposal/list?status=3,4,5,6,7,8&ex=1')">
					<view class="title">{{ num5 }}</view>
					<view>办理中</view>
				</view>
				<view class="plus-item bg94" @click="listTo('/pagesB/proposal/list?status=8')">
					<view class="title">{{ num8 }}</view>
					<view>已办结</view>
				</view>
			</view>
		</view>

		<view class="com-h2"><text class="h2-title">我的建议</text></view>
		<view class="list-box">
			<view class="list-info_02" v-for="(item, index) of proposalList" :key="item.id" @click="navTo(item)">
				<view class="left">
					<view class="info-title">{{ item.title }}</view>
					<view class="info-btm">
						<view class="name clamp">{{ item.leaderName }}</view>
						<text class="line"></text>
						<view class="time">{{ item.createTime | parseTime('{y}-{m}-{d}') }}</view>
					</view>
				</view>
				<view class="right" :class="[index % 2 == 0 ? 'bg1' : 'bg2']">建议</view>
			</view>
			<u-loadmore :status="loading" />
		</view>
	</view>
</template>

<script>
import { mapState } from 'vuex';
export default {
	data() {
		return {
			numAll: 0,
			num5: 0,
			num6: 0,
			num8: 0,
			num21: 0,
			num23: 0,
			num25: 0,
			num101: 0,
			filterType: 0,
			keyword: '',
			proposalList: [],

			motion: {
				ciId: '',
				jieId: '',
				kind: '',
				nodeStatus: '',
				isOpen: '',
				title: '',
				type: ''
			},
			loading: 'loadmore'
		};
	},
	onLoad() {
		this.loadLogin();
		this.loadAll();
		this.loadData();
	},
	onPullDownRefresh() {
		this.loadAll();
		this.loadData('refresh');
	},
	onReachBottom() {
		if (this.loading == 'loadmore') this.loadData('add');
	},
	computed: {
		...mapState(['userInfo'])
	},
	methods: {
		loadLogin() {
			if (this.userInfo.Authorization) {
				this.clientCode = this.userInfo.sysUser.clientCode;
				this.userId = this.userInfo.sysUser.id;
				
				this.motion.jieId = this.userInfo.jieCi.pid;
				this.motion.ciId = this.userInfo.jieCi.id;
				
				this.pageNum = 1;
				this.pageSize = 10;
			} else {
				this.$logout();
			}
		},
		loadData(type = 'add') {
			if (this.loading == 'loading') {
				return false;
			}
			if (type == 'add') {
				if (this.loading == 'nomore') {
					return false;
				}
				this.loading = 'loading';
			} else {
				this.loading = 'loading';
			}
			if (type != 'add') {
				this.pageNum = 1;
			}
			if (this.filterType == 0) {
				this.motion.isOpen = '';
			} else {
				this.motion.isOpen = '3';
			}

			let data = {
				pageNum: this.pageNum,
				pageSize: this.pageSize,
				clientCode: this.clientCode,
				motion: this.motion
			};
			if (this.filterType == 0) {
				data.currentUserId = this.userId;
				this.$request('/motion/myList', data, {
					load: true
				}).then((res) => {
					let count = 0;
					if (type != 'add') {
						uni.stopPullDownRefresh();
						this.proposalList = [];
					}
					this.loading = this.pageNum < Math.ceil(res.data.total / this.pageSize) ? 'loadmore' : 'nomore';
					this.pageNum = this.pageNum + 1;
					this.proposalList = this.proposalList.concat(res.data.records);
					this.loaded = true;
					if (this.proposalList.length <= 0) {
						this.loading = 'nodata';
					}
				});
			} else {
				this.$request('/motion/list', data, {
					load: true
				}).then((res) => {
					let count = 0;
					if (type != 'add') {
						uni.stopPullDownRefresh();
						this.proposalList = [];
					}
					this.loading = this.pageNum < Math.ceil(res.data.total / this.pageSize) ? 'loadmore' : 'nomore';
					this.pageNum = this.pageNum + 1;
					this.proposalList = this.proposalList.concat(res.data.records);
					this.loaded = true;
					if (this.proposalList.length <= 0) {
						this.loading = 'nodata';
					}
				});
			}
		},
		loadAll() {
			let data = {
				jieId: this.userInfo.jieCi.pid,
				ciId: this.userInfo.jieCi.id,
				currentUserId: this.userId,
				clientCode: this.clientCode
			};
			this.$request('/motion/statistics/indexCount', data).then((res) => {
				this.numAll = res.data.count_all;
				this.num5 = res.data.count_5;
				this.num6 = res.data.count_6;
				this.num8 = res.data.count_8;
				this.num21 = res.data.count_21;
				this.num23 = res.data.count_23;
				this.num25 = res.data.count_25;
				this.num101 = res.data.countLian;
			});
		},
		search(e) {
			this.keyword = e;
			this.loadData('refresh');
		},
		type(e) {
			this.filterType = e;
			this.loadData('refresh');
		},
		listTo(url) {
			uni.navigateTo({
				url: url
			});
		},
		navTo(item) {
			uni.navigateTo({
				url: '/pagesB/proposal/detail?id=' + item.id
			});
		}
	}
};
</script>

<style lang="scss">
.list-box {
	margin-top: -30rpx;
	padding: 0 30rpx;
	// border-radius: 30rpx;
	background-color: #fff;
}

.plus-inner {
	margin-top: -30rpx;
}

.list-info_02 .right {
	width: 236rpx;
	height: 148rpx;
	font-size: 17px;
	color: #fff;
	line-height: 148rpx;
	text-align: center;
	background: #d0021b no-repeat center;
	background-size: 100%;
	text-shadow: rgba(0, 0, 0, 0.4) 0em 0.12em 0.2em;
	letter-spacing: 2px;
}
</style>
